package com.moyq5.permit.center.make;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import com.moyq5.mvcmaker.MakerFactory;
import com.moyq5.mvcmaker.module.DaoImplModule;
import com.moyq5.mvcmaker.module.DaoModule;
import com.moyq5.mvcmaker.module.EntityModule;
import com.moyq5.mvcmaker.module.DataFeignServerControllerModule;
import com.moyq5.mvcmaker.module.DataFeignClientModule;
import com.moyq5.mvcmaker.module.FormModule;
import com.moyq5.mvcmaker.module.FrameworkModule;
import com.moyq5.mvcmaker.module.JacksonFilterModule;
import com.moyq5.mvcmaker.module.JacksonMixinModule;
import com.moyq5.mvcmaker.module.ProjectModule;
import com.moyq5.mvcmaker.module.SearchModule;
import com.moyq5.mvcmaker.module.ServiceImplModule;
import com.moyq5.mvcmaker.module.ServiceModule;

/**
 * Hello world!
 *
 */
public class App {
	private static final String projectName = "permit-center";
	private static final String projectPackage = "com.moyq5.permit.center";
	public static void main(String[] args) {

		ProjectModule project = createProjectModule();

		DataFeignClientModule feign = new DataFeignClientModule(project, projectName + "-feign-client", projectPackage + ".feign.client");

		JacksonMixinModule feignMixin = new JacksonMixinModule(project, projectName + "-feign-server",
				projectPackage + ".feign.server.jackson.mixin");
		JacksonFilterModule feignFilter = new JacksonFilterModule(project, projectName + "-feign-server",
				projectPackage + ".feign.server.jackson.filter");
		DataFeignServerControllerModule feignControler = new DataFeignServerControllerModule(project, projectName + "-feign-server",
				projectPackage + ".feign.server.controller");

		project.addModule(feign);
		project.addModule(feignMixin);
		project.addModule(feignFilter);
		project.addModule(feignControler);

		MakerFactory.execute(project);

		// ###########################

		project = createProjectModule();

		JacksonMixinModule webMixin = new JacksonMixinModule(project, projectName + "-web-server",
				projectPackage + ".web.jackson.mixin");
		JacksonFilterModule webFilter = new JacksonFilterModule(project, projectName + "-web-server",
				projectPackage + ".web.jackson.filter");
		FormModule webForm = new FormModule(project, projectName + "-web-server", 
				projectPackage + ".web.form");

		project.addModule(webMixin);
		project.addModule(webFilter);
		project.addModule(webForm);

		MakerFactory.execute(project);
	}

	private static ProjectModule createProjectModule() {
		String path = App.class.getClassLoader().getResource("").getPath();
		path = path.substring(0, path.indexOf("/"+ projectName +"-make"));
		try {
			path = URLDecoder.decode(path, "UTF-8");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}

		ProjectModule project = new ProjectModule(path, projectName, projectPackage);

		// 核心公共模块
		project.addModule(new FrameworkModule(project, "mvc-framework-core", "com.moyq5.mvc.framework"));
		project.addModule(new EntityModule(project, projectName + "-bean", projectPackage + ".bean.entity"));
		project.addModule(new SearchModule(project, projectName + "-bean", projectPackage + ".bean.search"));
		project.addModule(new DaoModule(project, projectName + "-feign-server", projectPackage + ".core.dao"));
		project.addModule(new DaoImplModule(project, projectName + "-feign-server", projectPackage + ".core.dao.impl"));
		project.addModule(new ServiceModule(project, projectName + "-feign-server", projectPackage + ".core.service"));
		project.addModule(new ServiceImplModule(project, projectName + "-feign-server", projectPackage + ".core.service.impl"));

		return project;
	}

}
